import React from 'react'
export default (props) => {
  const {onAddList} = props
  const getVal = (e) => {
    if(e.keyCode === 13) {
      if(!e.target.value.trim()) return
      onAddList(e.target.value)
      e.target.value = ''
    }
  }
  return (
    <header>
      <section>
        <form action="#" id="form" onSubmit={(e) => e.preventDefault()} onKeyUp={getVal}>
          <label htmlFor="title">ToDoList</label>
          <input type="text" id="title" name="title" placeholder="添加ToDo" required="required" autoComplete="off" />
        </form>
      </section>
    </header>
  )
}
